package com.baijiaoxi.common.model.excel;

import lombok.Data;

import java.util.HashMap;
import java.util.Map;

@Data
public class Column<T> {
    protected String title;
    protected String key;

    protected int width = 20;//行宽
    protected Map<String, String> reflectMap;//需要值转换的
    protected T extra;
    protected String dateFormat;

    public Column setDateFormat(String dateFormat) {
        this.dateFormat = dateFormat;
        return this;
    }

    public Column setTitle(String title) {
        this.title = title;
        return this;
    }

    public Column setKey(String key) {
        this.key = key;
        return this;
    }

    public Column setWidth(int width) {
        this.width = width;
        return this;
    }

    public <T> Column setReflectMap(Map<T, String> reflectMapP) {
        this.reflectMap = new HashMap<>();
        if (reflectMapP != null && !reflectMapP.isEmpty())
        for (T key : reflectMapP.keySet()) {
            reflectMap.put(key.toString(), reflectMapP.get(key));
        }
        return this;
    }

    public Column setExtra(T extra) {
        this.extra = extra;
        return this;
    }

    public Column() {
    }

    public Column(String key) {
        this.key = key;
    }

    public Column(String key, String title) {
        this.title = title;
        this.key = key;
    }

    public Column(String key, String title, T extra) {
        this.title = title;
        this.key = key;
        this.extra = extra;
    }


    public Column(String key, String title, int width) {
        this.title = title;
        this.key = key;
        this.width = width;
    }

    public <T> Column(String key, String title, Map<T, String> reflectMap) {
        this.title = title;
        this.key = key;
        setReflectMap(reflectMap);
    }

    public <T> Column(String key, String title, int width, Map<T, String> reflectMap) {
        this.title = title;
        this.key = key;
        this.width = width;
        setReflectMap(reflectMap);
    }

    public static Column build(String key, String title) {
        return new Column(title, key);
    }

    public static Column build(String key) {
        return new Column(key);
    }

    public static Column build() {
        return new Column();
    }


}
